package com.dcdata.common;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.java.Log;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author: xinmi
 * @date: 2020/11/23
 * @description:
 */
@Log
public class dataReadAndShow {

    public static void main(String[] argc){
        String file = "Card2020_11_23.txt";

        Date latestDate = null;

        Date latestDateRksj = null;

        Date latestDateParse = null;

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        try {
            BufferedReader br1 = new BufferedReader(new FileReader(file));

            String line1 = null;

            while( (line1 = br1.readLine()) != null ){
                DateParse.Card card = JSON.parseObject(line1, DateParse.Card.class);

                Date tradeDate = card.getTradedatetime();

                if (latestDate != null){
                    if(latestDate.before(tradeDate))
                        latestDate = tradeDate;
                } else
                    latestDate = tradeDate;

                String preDay = sdf.format(tradeDate);
                log.info(preDay);

                Date rksj = card.getRksj();
                if (latestDateRksj != null){
                    if(latestDateRksj.before(rksj))
                        latestDateRksj = rksj;
                } else
                    latestDateRksj = rksj;

                String preDayRksj = sdf.format(rksj);

                log.info(preDayRksj);

                Date parseDay = card.getParsedatetime();
                if (latestDateParse != null){
                    if(latestDateParse.before(parseDay))
                        latestDateParse = parseDay;
                } else
                    latestDateParse = parseDay;

                String preDayParse = sdf.format(parseDay);

                log.info(preDayRksj);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        String latestDayStr = sdf.format(latestDate);

        log.info("the latest trade day is " + latestDayStr);

        String latestDayRksjStr = sdf.format(latestDateRksj);

        log.info("the latest rksj day is " + latestDayRksjStr);

        String latestDateParseStr = sdf.format(latestDateParse);

        log.info("the latest parse day is " + latestDateParseStr);

    }

    @Data
    @AllArgsConstructor
    public class Card{
        private int busid;
        private Date tradedatetime;
        private Date rksj;
        private int lineid;
        private String usertype;
        private Date parsedatetime;
        private int isqr;
        private int stationid;
    }
}
